<?php defined('SYSPATH') OR die('No direct access allowed.');

class Collectioncontent_Controller extends Viewbase_Controller{
	public function __construct(){
		$this->modelname='content';
		$this->controllername='collectioncontent';
		$this->parent_column='collection_id';
		
		$this->forms=array();
		parent::__construct();
	}	

	public function __preprocess_post($model){
		if($model->id=='0'){
			$model->created_by=$this->auth->get_user()->id;
		}else{
			$model->modified_by=$this->auth->get_user()->id;
		}
		eval($model->contentmodule->preprocess_post);
		return ($model);	
	}
	
	public function __postprocess_model($model){
	
		//$model->shortname=inflector::underscore($model->title).'_'.$model->id;
		//$model->save();
		
		
		if($this->input->post('formtype')=="addcategories"){
			if($this->input->post('contcatarray')){
				$model->contcategories=$this->input->post('contcatarray');
			}else{
				$model->contcategories=array();	
			}
			
			$model->save();	
	
		}else{
		
			if($model->shortname==""){
				$model->shortname=url::title($model->title);
			}
			
			if(!$model->shortname_check($model->shortname)){
				$model->shortname=url::title($model->title).'_'.$model->id;
				$model->save();
			}
		}
		
		
	}
}